package com.object.oriented.exam.system8.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.object.oriented.exam.system1.dao.KnowledgeMapping;
import com.object.oriented.exam.system1.entity.Knowledge;
import com.object.oriented.exam.system1.entity.Problem;
import com.object.oriented.exam.system1.service.ProblemService;
import com.object.oriented.exam.system2.entity.ProblemProperty;
import com.object.oriented.exam.system2.service.ProblemPropertyService;
import com.object.oriented.exam.system5.entity.Answer;
import com.object.oriented.exam.system8.entity.Question;
import com.object.oriented.exam.system8.service.QuestionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xdf
 * @date 2023-06-20
 */
@Service
public class QuestionServiceImpl implements QuestionService {
    @Resource
    ProblemService problemService;

    @Resource
    KnowledgeMapping knowledgeMapping;

    @Resource
    ProblemPropertyService problemPropertyService;

    @Override
    public Question getQuestion(Answer answer) {
        Question question =new Question();

        question.setProblemId(answer.getQuestionId());
        question.setResult(answer.getAnswer());

        // 题目信息
        Problem problem=problemService.getById(answer.getQuestionId());
        if(problem!=null){
            BeanUtils.copyProperties(problem, question);
            // 知识点
            Knowledge knowledge=knowledgeMapping.selectById(problem.getKnowledgeId());
            if(knowledge!=null){
                question.setKnowledgeId(problem.getKnowledgeId());
                question.setKnowledge(knowledge.getTitle());
            }
        }

        // 题目性质
        ProblemProperty problemProperty=problemPropertyService.getOne(new QueryWrapper<ProblemProperty>().eq("question_id",answer.getQuestionId()));
        if(problemProperty!=null){
            BeanUtils.copyProperties(problemProperty, question);
        }

        return question;
    }
}
